//This 2d3d browser use the chrome module and mouse and keyboard inputs are working in this one.
include('shared.lua')

ENT.RenderGroup = RENDERGROUP_BOTH

hook.Add("CanMousePress", "DisableGoogle", function()

	for _, v in pairs( ents.FindByClass( "google" ) ) do
		if v.Browser && v.MouseRayInteresct && v:MouseRayInteresct() then
			return false
		end
	end

end )

-- local res = 0.059375
-- local scale = 0.065
-- local width = 57
-- local height = 38
local format = 1.705
local screenheight = 33
local screenwidth = screenheight * format
local width = 1024
local height = width / format
local res = screenwidth / width

MakeRT(ENT, "ChromeRT", 1024, false)
SetupBrowserMat(ENT, "chrome/browser", "chrome/mouse/mouse", width, height, screenwidth, screenheight, format, res)

function ENT:FinishLoading()
	print("Loading Done.")
end

function ENT:LoadingURL(url, status)
	self.LoadedURL = url
	print("Loading: " ..url.. "\n Status:" ..tostring(status).. ".\n")
end

local URLAlpfa = 128

function ENT:DrawTranslucent()
	if !self.Browser then return end

	self:BaseBrowserDraw(self.LoadedURL, Color(128, 128, 128, URLAlpfa), Color(0, 0, 100, URLAlpfa))
end

function ENT:Draw()
	self:DrawModel()
end

local startsite = "http://www.google.com/"

function ENT:Initialize()
	self:InitBrowser()
	--self.Browser:LoadURL(startsite)
end


function ENT:GetPosBrowser()
	return self.Entity:GetPos() + (self.Entity:GetForward() * 6.1) + (self.Entity:GetUp() * 2.385) + (self.Entity:GetRight() * 0.065)
end

local URL2 = ""
local HideURL = false

function ENT:Think()
	if (self.Browser) then
		self:MouseThink()
		self.Browser:Update()

		HideURL = self:NBool("ShowURL")

		if(HideURL == true) then
			URLAlpfa = 0
		elseif(HideURL == false) then
			URLAlpfa = 128
		end


		local URL1 = self:NString("URL") or startsite
		if (type(URL1) == "string" and URL1 ~= "") then
			if (URL1 ~= URL2) then
				self.Browser:LoadURL(URL1)
				URL2 = URL1
			end
		end
	end

	self.Entity:NextThink(CurTime()+0.01)
	return true
end